"""
    通过继承创建线程
    GIL全局解释器锁
    获取GIL，执行线程方法，释放GIL
"""
import random
import threading
import time

count = 0
lock = threading.Lock()

class EricThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)

    def run(self):
        global count
        lock.acquire()
        sleep = random.randint(5,10)*0.01
        time.sleep(sleep)
        count += 1
        print(f'睡眠{sleep}秒，执行完成{count}')
        lock.release()

for i in range(100):
    thread = EricThread()
    thread.start()
    thread.join()
print(count)